<!DOCTYPE html>
<html>
  <head>
    <title>JRuby Embed OSGi support</title>
  </head>
  <body>
    <h1>JRuby Embed OSGi support</h1>
    <p>
      Extends the <a href="../">jruby.embed APIs</a>. Access classes, ruby and libraries contained in OSGi bundles.
    </p>
    <p>
      Example: use EclipseRT Web Starter Kit to run some ruby servlets and access
      some java objects.
    </p>
    <p>
      This code was originally developed by <a rel="nofollow" href="https://github.com/intalio/org.jruby.osgi/">Intalio</a>.
    </p>
    <h2>org.jruby.embed.osgi.OSGiScriptingContainer extends ScriptingContainer</h2>
    <p>
      Java code in an OSGi bundle:
    </p>
    <pre>
      OSGiScriptingContainer container = new OSGiScriptingContainer();
      container.runScriptlet(bundle, "/ruby/extend_MyClass.rb")
    </pre>
    <p>
      The bundle is lazily added to JRuby’s ClassPath.
    </p>
    <p>
      where 'extend_MyClass.rb’ reads:
    </p>
    <pre>
      class Java::OrgJrubyOsgiTestSample::MyClass
      def say_hello
      puts "hello"
      end
      end
    </pre>
    <p>
      It is also possible to add OSGi bundles to JRuby’s ClassPath from
      java:
    </p>
    <pre>
      container.addToClassPath(bundle)
    </pre>
    <h2>require 'bundle:/bundle.symbolic.name’</h2>
    <p>
      Define ruby libraries contained in an osgi bundle:
    </p>
    <pre>
      require 'osgibundle:/org.jruby.embed.osgi.test.samplebundle'
      class Java::OrgJrubyOsgiTestSamplebundle::MyOtherClass
      def say_hello_as_well
      puts "hello_as_well"
      end
      end
    </pre>
    <p>
      Access a ruby file inside a bundle:
    </p>
    <pre>
      require 'osgibundle:/org.jruby.embed.osgi.test/ruby/extend_MyClass.rb'
    </pre>
  </body>
</html>
